package com.snail.common;

import java.net.URL;
import java.net.URLClassLoader;

public class PluginClassLoader extends URLClassLoader {
    public PluginClassLoader(URL[] urls) {
        super(urls, ClassLoader.getSystemClassLoader().getParent());
    }

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        synchronized (getClassLoadingLock(name)) {
            // 优先从插件加载类
            try {
                Class<?> aClass = super.findClass(name);
                return aClass;
            } catch (ClassNotFoundException e) {
                Class<?> aClass = super.loadClass(name);
                return aClass;
            }
        }
    }
}